Repository navigation
feat: report failure diagnostics in relay test:fail events - #15
Merged
Merged
Conversation
twd-js attaches a diagnostics snapshot to a failed test (BRIKEV/twd #335) naming the route the test was on and which mock rules never fired. The relay supplies its own `events` object to `TestRunner`, so the sidebar's `onFail` never runs under the relay and that block was being dropped. `onFail` now composes the block above the error message, matching the sidebar and `runner-ci` — the accessible-roles dump lives inside `err.message` and would otherwise bury it. `src/cli/run.ts` needed no change; it already indents multi-line errors. The renderer is a deliberate port of twd-js's internal `src/utils/diagnostics.ts` rather than an import. twd-js keeps `formatDiagnostics` private, and its only public entry pulls in the sidebar, chai and the theme (~470 KB) — far too much to load into the page for a pure string formatter. The relay needs only the data, which already arrives on the handler via `twd-js/runner`. `diagnostics.spec.ts` mirrors twd-js's own spec so the two formats stay byte-identical. No peer-range bump: nothing new is imported from twd-js. On a version that does not report diagnostics the block is simply absent, as it is for a test that failed one attempt then passed on retry. Adds the first integration test that drives the real browser client against a real relay, verified red-green: removing the composition from `onFail` fails it. That lifts createBrowserClient.ts coverage 0% -> 49%. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Surfaces the failure-diagnostics block from BRIKEV/twd#335 in relay runs, so a CLI failure names the route the test was on and which mock rules never fired.
Why the relay showed nothing
createBrowserClientsupplies its owneventsobject toTestRunner, so the sidebar'sonFailnever runs under the relay — ours does, and it sent onlyerror.message. The block now goes above the message, matching the sidebar andrunner-ci: the accessible-roles dump lives insideerr.messageand would otherwise bury it.src/cli/run.tsneeded no change — it already indents multi-line errors.The renderer is a port, not an import
NEXT-DIAGNOSTICS.mdproposedawait import('twd-js')to reachformatDiagnostics. I went the other way, for two reasons:twd-js/runner. That is a lot to pull into the page for a pure string formatter.formatDiagnosticsis still private ontwd/mainafter #335 merged, and there is no light subpath for it. Importing it would need a second twd-js change and a second release.The relay needs only the data, and that already arrives on the handler through
twd-js/runner, which we import today. Sosrc/browser/diagnostics.tsports the ~25-line pure renderer, in the same spirit as the existing structuralTwdHandlerandVitePlugininterfaces.The trade-off: the format is now duplicated and can drift.
src/tests/browser/diagnostics.spec.tsmirrors twd-js's own spec case-for-case to make drift show up as a failure, andCLAUDE.mdrecords that the port must be updated if twd-js's format changes. If you'd rather have a single source of truth, the alternative is exporting the formatter from a light twd-js subpath and importing it — happy to switch.No peer-range bump
Nothing new is imported from twd-js, so
>=1.4.0stands. On a twd-js that doesn't report diagnostics the block is simply absent — same as for a test that failed one attempt then passed on retry (runner.tsclearsdiagnosticsat the start of each attempt).This is a safe no-op until you publish. Merging before the release changes nothing at runtime; the block starts appearing the moment the new twd-js is installed, with no further relay change.
Tests
diagnostics.spec.ts— 9 cases mirroring twd-js's spec: header/footer rule, location alone, summary when all triggered, single miss inline, several misses listed, cap at five plus+N more, and the no-diagnostics passthrough.createBrowserClient.diagnostics.spec.ts— the first test that drives the real browser client against a real relay. The existing browser suite simulates a browser-role connection, so it could not catch the composition being removed fromonFail. Verified red-green: reverting the one-line wiring fails this test. Side effect:createBrowserClient.tscoverage goes 0% → 49%.run.spec.ts— one case proving the block survives to the terminal one line per row, correctly indented.Verification
npm run test:ci→ 96/96 passing, 11 files (was 85/9)npx tsc --noEmit→ cleannpm run build→ OK; 3 rolled-up.d.ts, 0 stub filesattw --pack .→node16 (from ESM)green on all 3 entriesnpm audit→ 0 vulnerabilitiesdiagnostics.tsat 100% statement coverageLeft out deliberately
test.logs = [error.message]at line 214 is still an assignment, not an append — your call perNEXT-DIAGNOSTICS.md, and its only effect is in the twd-js sidebar, which nothing here can verify. Worth noting the window is narrower than the doc suggests:runner.tsalready resetstest.logs = []at the start of every attempt, so only entries pushed during the test body are lost.🤖 Generated with Claude Code